<?php
/*
 * @version		2.2.0
 * @category	Plugin
 * @package		Joomla
 * @author		Original Author <serafinobilotta@hotmail.com>
 * @license		GNU/GPL, see http://www.gnu.org/licenses/gpl-2.0.html
 * @link		http://www.p2warticles.com/2011/06/scrolling-share-bar-joomla/
 * @since		2.0.0
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
 
jimport('joomla.form.formfield');
 
class JFormFieldJqueryui extends JFormField {
 
	protected $type = 'Jqueryui';
 
	// getLabel() left out
 
	public function getInput() {
		$doc = & JFactory::getDocument();
        $doc->addScript("https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
		$doc->addScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js");
		$doc->addScript("../plugins/system/scrollingsharebar/js/jquery.ui.selectmenu.js");
		$doc->addScript("../plugins/system/scrollingsharebar/js/jquery.multiselect.js");
		$doc->addScript("../plugins/system/scrollingsharebar/js/jquery.multiselect.filter.js");
		$doc->addScriptDeclaration('jQuery.noConflict();
function restoreOrder() {
    var list = jQuery("#format ul");
    if (list == null) return;
    var old = jQuery("#jform_params_positions").val();
    var IDs = old.split(",");
    var items = list.sortable("toArray");
	var rebuild = new Array();
    for (var v = 0, len = items.length; v < len; v++) {
        rebuild[items[v]] = items[v];
    }
    for (var i = 0, n = IDs.length; i < n; i++) {
        var itemID = IDs[i] + "_";
        if (itemID in rebuild) {
            var item = rebuild[itemID];
            var child = jQuery("ul.ui-sortable").children("#" + item);
            var savedOrd = jQuery("ul.ui-sortable").children("#" + itemID);
            child.remove();
            jQuery("ul.ui-sortable").filter(":first").append(savedOrd);
        }
    }
}');
		$doc->addScriptDeclaration("
jQuery(function() {
    jQuery('.panel, #jform_params_positions-lbl, #jform_params_positions').hide();
    jQuery('#sortable').sortable({
        opacity: 0.6,
        update: function(event, ui) {
            aggiornaTesto();
        }
    });


    function aggiornaTesto() {
        ids = [];
        jQuery('#sortable input:checkbox').each(function(n) {
            ids.push(jQuery(this).attr('value'));
        });
        jQuery('#jform_params_positions').val(ids);
    }
    restoreOrder();
    jQuery( '#accordion' ).accordion({ collapsible:true,
                                       autoHeight:false});
	jQuery( '[type=checkbox]' ).button();
    jQuery('.selectmenu').selectmenu({
				style:\"popup\", 
				maxHeight: 200
	});
	jQuery('#jform_params_e_articles, #jform_params_e_categories').multiselect().multiselectfilter();
	
});");
		$doc->addScriptDeclaration('jQuery(function() {
		if ( !jQuery( "<canvas/>" )[0].getContext ) {
			jQuery( "<div/>" ).text(
				"Your browser doesn\'t support canvas, which is required for this demo. " +
				"Give Firefox 3 a try!"
			).appendTo( "#graphs" );
			return;
		}

		var i = 0,
			width = 100,
			height = 100;
		jQuery.each( jQuery.easing, function( name, impl ) {
			// skip linear/jswing and any non functioning implementation
			if ( !jQuery.isFunction( impl ) || /jswing/.test( name ) ) {
				return;
			}
			var graph = jQuery( "<div/>" ).addClass( "graph" ).appendTo( "#graphs" ),
				text = jQuery( "<div/>" ).text( ++i + ". " + name ).appendTo( graph ),
				wrap = jQuery( "<div/>" ).appendTo( graph ).css( \'overflow\', \'hidden\' ),
				canvas = jQuery( "<canvas/>" ).appendTo( wrap )[ 0 ];
			canvas.width = width;
			canvas.height = height;
			var drawHeight = height * 0.8,
				cradius = 10;
				ctx = canvas.getContext( "2d" );
			ctx.fillStyle = "black";

			ctx.beginPath();
			ctx.moveTo( cradius, 0 );
			ctx.quadraticCurveTo( 0, 0, 0, cradius );
			ctx.lineTo( 0, height - cradius );
			ctx.quadraticCurveTo( 0, height, cradius, height );
			ctx.lineTo( width - cradius, height );
			ctx.quadraticCurveTo( width, height, width, height - cradius );
			ctx.lineTo( width, 0 );
			ctx.lineTo( cradius, 0 );
			ctx.fill();

			ctx.strokeStyle = "#555";
			ctx.beginPath();
			ctx.moveTo( width * 0.1, drawHeight + .5 );
			ctx.lineTo( width * 0.9, drawHeight + .5 );
			ctx.stroke();

			ctx.strokeStyle = "#555";
			ctx.beginPath();
			ctx.moveTo( width * 0.1, drawHeight * .3 - .5 );
			ctx.lineTo( width * 0.9, drawHeight * .3 - .5 );
			ctx.stroke();
			
			ctx.strokeStyle = "white";
			ctx.beginPath();
			ctx.lineWidth = 2;
			ctx.moveTo( width * 0.1, drawHeight );
			jQuery.each( new Array( width ), function( position ) {
				var val = impl( 0, position, 0, 1, height );
				if ( /linear|jswing/.test( name ) ) {
					val = position / width;
				}
				ctx.lineTo( position * 0.8 + width * 0.1,
					drawHeight - drawHeight * val * 0.7 );
			});
			ctx.stroke();
			graph.click(function() {
				wrap
					.animate( { height: "hide" }, 2000, name )
					.delay( 800 )
					.animate( { height: "show" }, 2000, name );
			});

			graph.width( width ).height( height + text.height() + 10 );
		});
	});');
		$doc->addStyleSheet("../plugins/system/scrollingsharebar/css/ui-darkness/jquery-ui-1.8.17.custom.css");
		$doc->addStyleSheet("../plugins/system/scrollingsharebar/css/ui.selectmenu.css");
		$doc->addStyleSheet("../plugins/system/scrollingsharebar/css/jquery.multiselect.css");
		$doc->addStyleSheet("../plugins/system/scrollingsharebar/css/jquery.multiselect.filter.css");
		$doc->addStyleDeclaration('
		#sortable { list-style-type: none;margin-left: -40px;}
        #sortable li { margin: 3px 3px 3px 0; padding: 1px; float: left; width: 80px; height: 90px; text-align: center;font-size:.8em }
	.ui-select-menu { float: left; margin-right: 10px; }
	select { width: 350px; }
	.ui-button{ width: 150px}
	#sortable li .ui-button{width: 80px;}
	.ui-widget{ margin:10px}
	.ui-accordion-content>li{
		margin-top:15px;
	}
	.graph {float: left;margin-left: 10px; font-size: 9px;}
	');
		
		
		return ;
	}
	public function getLabel() {
		return '</label></li></ul></fieldset></div></div><div>
		<div id="accordion"><h3><a href="#">Basic Settings</a></h3><div>';
	}
}